home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / Optimize Image in Fireworks.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  4.4 KB  |  148 lines

  1. // Copyright 1998, 1999, 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2. //
  3. // Command: Optimize Image in Fireworks
  4. //
  5. // This formless command attempts to find and launch 
  6. // a Fireworks optimization session on a selected image
  7. // within dw.
  8. //
  9. // Most of the work to do this is implemented in the
  10. // extension DLL FWLaunch.DLL.
  11. //
  12. // **************** Commands API *****************
  13.     
  14. function canAcceptCommand()
  15. {
  16.   var retVal = false;
  17.   // First validate that there's a document
  18.   var dom = dw.getDocumentDOM();
  19.   if (dom) {
  20.     // Don't bother to check if a valid version of Fireworks is installed, 
  21.       // because we'll alert the user later about where they can download
  22.       // Fireworks for a free trial if they don't have it installed. 
  23.     // return TRUE if an image is selected
  24.     var node = dom.getSelectedNode();
  25.     if (node != null && node.nodeType == Node.ELEMENT && node.tagName  == "IMG"  && node.getAttribute( "src" )){
  26.       var src = node.getAttribute( "src" );
  27. //      if ( dom.IsImageLocked( src ) == false )
  28.         retVal = true;
  29.     }
  30.   }
  31.   return retVal;
  32. }
  33.    
  34. //---------------    LOCAL FUNCTIONS   ---------------
  35.  
  36.    function optimizeImage()
  37.    {
  38.       var dom = dw.getDocumentDOM();
  39.  
  40.       // If we can't find the FWLaunch extension, abort.
  41.       if (typeof( FWLaunch ) == "undefined")
  42.       {
  43.         alert( MSG_Err_FireworksDllNotInstalled );
  44.         return;
  45.       }
  46.  
  47.          // If they don't have Fireworks 2 or greater installed, give them 
  48.       // the link to the Macromedia site so they can get a free trial version.
  49.       if ( !FWLaunch.validateFireworks(2.0) )
  50.       {
  51.         alert( MSG_Err_FireworksNotInstalled );
  52.         return;
  53.       }
  54.       
  55.       // First check to see if we may launch a session; this
  56.       // currently always returns TRUE for windows, but may
  57.       // return FALSE on the Mac if there's already an 
  58.       // optimization session in progress
  59.       //
  60.       if ( !FWLaunch.mayLaunchFireworks() )
  61.       {
  62.          alert( MSG_Err_MayNotLaunch );
  63.          return;
  64.       }
  65.    
  66.       // Make sure the file has been saved to disk first so
  67.       // we know the document path (which the DLL uses, 
  68.       // among other things, to resolve doc-relative urls
  69.       // and determine working directory (on windows)).
  70.       //
  71.       if (dom.URL == "" ) {
  72.          if (confirm(MSG_Err_FileNotSaved) && dw.canSaveDocument(dom)) {
  73.            dw.saveDocument(dom);
  74.          }
  75.          if (dom.URL == "" )
  76.            return;
  77.          //otherwise file saved, so continue
  78.       }
  79.       // canAcceptCommand() should have validated that the 
  80.       // selection is an image node; go no further if we
  81.       // don't have a valid SRC attribute
  82.       //
  83.       var node      = dom.getSelectedNode();
  84.       var imageSrc  = node.getAttribute( "src" );
  85.       var width     = node.getAttribute( "width" );
  86.       var height    = node.getAttribute( "height" );
  87.  
  88.       if ( !imageSrc )
  89.       {
  90.          alert( MSG_Err_InvalidUsage );
  91.          return;
  92.       }
  93.       
  94.       // Force width and height to invalid state if they're
  95.       // not defined
  96.       //
  97.       if ( !width )
  98.          width = -1;
  99.          
  100.       if ( !height )
  101.          height = -1;
  102.       
  103.       // Fix up site relative URLs here...
  104.       //
  105.       var siteRoot = dw.getSiteRoot();
  106.       if ( siteRoot )
  107.       {
  108.          if ( imageSrc.indexOf( '/' ) == 0 )
  109.             imageSrc = siteRoot + imageSrc.substring( 1 );
  110.       }
  111.  
  112.       dw.fireworksCheckout( imageSrc );
  113.  
  114.       // Now invoke FWLaunch and process the return code
  115.       //
  116.       var rc = FWLaunch.optimizeInFireworks( unescape( dom.URL )
  117.                                            , unescape( imageSrc ) 
  118.                                            , width
  119.                                            , height );
  120.       switch( rc )
  121.       {
  122.          case 0:
  123.             break; // success!
  124.          
  125.          case 1:
  126.             alert( MSG_Err_InvalidUsage );
  127.             break;
  128.             
  129.          case 2:
  130.             alert( MSG_Err_ResponseFile );
  131.             break;
  132.             
  133.          case 3:
  134.             alert( MSG_Err_Dreamweaver );
  135.             break;
  136.          
  137.          case 4:
  138.             alert( MSG_Err_Fireworks );
  139.             break;
  140.             
  141.          default:
  142.             alert( MSG_Err_UnrecognizedRC + rc );
  143.             break;
  144.       }
  145.  
  146.       return;         
  147.    }
  148.